// pages/feedback/feedback.js
const app = getApp()
import api from '../../utils/api'
Page({

  /**
   * 页面的初始数据
   */
  
  data: {
    navBarHeight: app.globalData.navBarHeight, //导航栏高度
    menuBotton: app.globalData.menuBotton, //导航栏距离顶部距离
    menuHeight: app.globalData.menuHeight, //导航栏高度
    userType: "",
    module1Number: "0",
    module2Number: "0",
    module3Number: "0",
    module4Number: "0",
    module5Number: "0",
    module6Number: "0",

    feedbacksToBeReplied: [],
    feedbacksToBeRepliedNumber: 0,
    feedbacksReplied: [],
    feedbacksRepliedNumber: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const _this = this
    if(options.userType){
      _this.setData({
        userType: options.userType
      })
    } else {
      _this.setData({
        userType: wx.getStorageSync('logindata').data.userType
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    const _this = this
    if(_this.data.userType == "07"){
      wx.request({
        url: api.cloudAllModule,
        method: "POST",
        data: {
          userId: wx.getStorageSync('workNo')
        },
        header: {
        'content-type': 'application/json' // 默认值
        },
        success(res) {
          if (res.data.data) {
            res.data.data.forEach( element => {
              if (element.moduleType == "01") {
                _this.setData({ module1Number: element.count })
              } else if (element.moduleType == "02") {
                _this.setData({ module2Number: element.count })
              } else if (element.moduleType == "03") {
                _this.setData({ module3Number: element.count })
              } else if (element.moduleType == "04") {
                _this.setData({ module4Number: element.count })
              } else if (element.moduleType == "05") {
                _this.setData({ module5Number: element.count })
              } else if (element.moduleType == "06") {
                _this.setData({ module6Number: element.count })
              }
            })
          }
        }
      })
    }
    wx.request({
      url: api.cloudGetAllQuestion,
      method: "POST",
      data: {
        replyStatus: '00',
        userId: wx.getStorageSync('workNo'),
        pageSize: 10,
        currentPage: 1,
        userType: wx.getStorageSync('logindata').data.userType
      },
      header: {
      'content-type': 'application/json' // 默认值
      },
      success(res) {
        if (res.data.data) {
          _this.setData({
            feedbacksToBeReplied: res.data.data.records,
            feedbacksToBeRepliedNumber: res.data.data.totalRecords
          })
        } else {
          _this.setData({
            feedbacksToBeReplied: [],
            feedbacksToBeRepliedNumber: 0
          })
        }
        // app.feedbackData.feedbacksToBeReplied = JSON.stringify(_this.data.feedbacksToBeReplied)
        app.feedbackData.feedbacksToBeRepliedNumber = _this.data.feedbacksToBeRepliedNumber
      }
    })

    wx.request({
      url: api.cloudGetAllQuestion,
      method: "POST",
      data: {
        replyStatus: '01',
        userId: wx.getStorageSync('workNo'),
        pageSize: 10,
        currentPage: 1,
        userType: wx.getStorageSync('logindata').data.userType
      },
      header: {
      'content-type': 'application/json' // 默认值
      },
      success(res) {
        if (res.data.data) {
          _this.setData({
            feedbacksReplied: res.data.data.records,
            feedbacksRepliedNumber: res.data.data.totalRecords
          })
        } else {
          _this.setData({
            feedbacksReplied: [],
            feedbacksRepliedNumber: 0
          })
        }
        // app.feedbackData.feedbacksReplied = JSON.stringify(_this.data.feedbacksReplied)
        app.feedbackData.feedbacksRepliedNumber = _this.data.feedbacksRepliedNumber
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  /**
   * 跳转到模块1页面
   */
  goToModule1: function (e) {
    wx.navigateTo({
      url: '/pages/feedbackAll/feedbackAll?module=01',
    })
  },
  /**
   * 跳转到模块2页面
   */
  goToModule2: function (e) {
    wx.navigateTo({
      url: '/pages/feedbackAll/feedbackAll?module=02',
    })
  },
  /**
   * 跳转到模块3页面
   */
  goToModule3: function (e) {
    wx.navigateTo({
      url: '/pages/feedbackAll/feedbackAll?module=03',
    })
  },
  /**
   * 跳转到模块4页面
   */
  goToModule4: function (e) {
    wx.navigateTo({
      url: '/pages/feedbackAll/feedbackAll?module=04',
    })
  },
  /**
   * 跳转到模块5页面
   */
  goToModule5: function (e) {
    wx.navigateTo({
      url: '/pages/feedbackAll/feedbackAll?module=05',
    })
  },
  /**
   * 跳转到模块6页面
   */
  goToModule6: function (e) {
    wx.navigateTo({
      url: '/pages/feedbackAll/feedbackAll?module=06',
    })
  },
  /**
   * 跳转到待回应页面
   */
  goToToBeReplied: function (e) {
    wx.navigateTo({
      url: '/pages/feedbackAll/feedbackAll?isReplied=f'
    })
  },
  /**
   * 跳转到已答复页面
   */
  goToReplied: function (e) {
    wx.navigateTo({
      url: '/pages/feedbackAll/feedbackAll?isReplied=t'
    })
  },
  /**
   * 跳转到反馈详情页面
   */
  goToFeedbackDetail: function (e) {
    wx.navigateTo({
      url: '/pages/feedbackDetailReply/feedbackDetailReply?feedbackId=' + e.currentTarget.dataset.feedbackid,
    })
  },
  /**
   * 返回上一页
   */
  goBack: function (e) {
    wx.navigateBack({
      delta: 1,
    })
  },
    /**
   * 跳转到新增反馈页面
   */
  goToAdd: function (e) {
    wx.navigateTo({
      url: '/pages/feedbackAdd/feedbackAdd',
    })
  },
  /**
   * 常见问题手册打开
   */
  openManual() {
    wx.navigateTo({
      url: '/pages/manual/manual',
    })
  }
})